/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package networktrain;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author benjamin
 */  
public class Recieve extends Thread {
    
    public Socket s;
    public int port;
    public BufferedReader in;
    
    
    public Recieve(Socket s) throws IOException{
        this.s=s;
        System.out.println("Reciever created");
        
        
    }
    
      public void run(){
        
            try {
                while (this.s.isConnected()) {
                    System.out.println("BufferedReader created");
                    in = new BufferedReader(new InputStreamReader(this.s.getInputStream()));
                    String tempString;
                    while(!s.isClosed()){
                        while (!(tempString = in.readLine()).equals("close")) {
                            System.out.println("Message Recieved");
                            System.out.println(tempString);
                        }
                    }
                }
            } catch (IOException ex) {
                Logger.getLogger(Recieve.class.getName()).log(Level.SEVERE, null, ex);
            }
      }
    
    

}
